import tkinter as tk
from tkinter import messagebox, StringVar
import pymssql
import pymysql
import PIL
from PIL import Image
from PIL import ImageTk


# 员工表的添加
def add_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 员工表(员工编号,员工姓名,员工密码,员工级别,员工电话,员工工资,备注) values('%s','%s','%s','%s','%s','%s','%s')" % (s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get(), s7.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def delete_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 员工表 where 员工编号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def select_yg():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 员工表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def show_result(result):
    for idx, row in enumerate(result):
        for col_idx, value in enumerate(row):
            label = tk.Label(window_function, text=value)
            label.grid(row=idx, column=col_idx)

def add_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 商品表(商品编号,商品名称,商品单价,供应商编号,商品简介,备注) values('%s','%s','%s','%s','%s','%s')" % (s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def delete_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 商品表 where 商品编号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def select_sp():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 商品表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def show_result(result):
    for idx, row in enumerate(result):
        for col_idx, value in enumerate(row):
            label = tk.Label(window_function, text=value)
            label.grid(row=idx, column=col_idx)

def add_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 供应商表(供应商编号,供应商名称,供应商简称,地址,公司电话,邮件,联系人,联系人电话,备注) values('%s','%s','%s','%s','%s','%s','%s','%s','%s')" % (s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get(), s7.get(), s8.get(), s9.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def delete_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 供应商表 where 供应商编号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def select_gys():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 供应商表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def show_result(result):
    for idx, row in enumerate(result):
        for col_idx, value in enumerate(row):
            label = tk.Label(window_function, text=value)
            label.grid(row=idx, column=col_idx)

def add_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 采购主表(采购清单号,员工编号,采购数量,采购总价,采购时间,备注) values('%s','%s','%s','%s','%s','%s')" % (s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def delete_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 采购主表 where 采购清单号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def select_cgzb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 采购主表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def show_result(result):
    for idx, row in enumerate(result):
        for col_idx, value in enumerate(row):
            label = tk.Label(window_function, text=value)
            label.grid(row=idx, column=col_idx)

def add_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "insert into 采购明细表(采购明细号,采购清单号,商品编号,采购数量,商品单价,商品总价,备注) values('%s','%s','%s','%s','%s','%s','%s')" % (s1.get(), s2.get(), s3.get(), s4.get(), s5.get(), s6.get(), s7.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据添加成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def delete_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "delete from 采购明细表 where 采购明细号='%s'" % (s1.get())
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        connect.commit()
        tk.messagebox.showinfo("提示", "数据删除成功")
    except:
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def select_cgmxb():
    # 连接数据库
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    # 创建光标
    cursor = connect.cursor()
    # 编写SQL语句
    sql = "select * from 采购明细表"
    # 执行SQL语句，并且输出完成提示信息，否则回滚
    try:
        cursor.execute(sql)
        result = cursor.fetchall()  # 获取查询结果
        connect.commit()
        show_result(result)  # 显示查询结果
    except Exception as e:
        print(f"查询出错: {e}")
        connect.rollback()
    # 关闭数据库连接，防止泄露
    connect.close()

def show_result(result):
    for idx, row in enumerate(result):
        for col_idx, value in enumerate(row):
            label = tk.Label(window_function, text=value)
            label.grid(row=idx, column=col_idx)
#######################################################################################################
#######################################################################################################
#######################################################################################################
def add_employee():# 添加员工界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1,s2,s3,s4,s5,s6,s7
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("添加员工信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="添加新员工", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工姓名：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工密码：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工级别：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工电话：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function, text="请输入员工资：").grid(row=6, column=0, padx=20, pady=20)
    tk.Label(window_function, text="备注：").grid(row=7, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    s7 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function, show=None, textvariable=s6).grid(row=6, column=1)
    entry7 = tk.Entry(window_function, show=None, textvariable=s7).grid(row=7, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="添加", command=add_yg).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back1_add).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()


def add_good():# 添加商品界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function_good
    global s1,s2,s3,s4,s5,s6
    # 生成窗口
    window_function_good = tk.Tk()
    # 窗口标题
    window_function_good.title("添加商品信息")
    # 窗口大小
    window_function_good.geometry('400x700')

    # 生成标签
    tk.Label(window_function_good, text="添加新商品", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function_good, text="请输入商品编号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function_good, text="请输入商品名称：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function_good, text="请输入商品单价：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function_good, text="请输入供应商编号：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function_good, text="请输入商品简介：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function_good, text="备注：").grid(row=6, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function_good, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function_good, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function_good, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function_good, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function_good, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function_good, show=None, textvariable=s6).grid(row=6, column=1)
    # 生成按钮
    button = tk.Button(window_function_good, text="添加", command=add_sp).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function_good, text="返回", command=back2_add).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function_good.update_idletasks()
    width = window_function_good.winfo_width()
    height = window_function_good.winfo_height()
    screenwidth = window_function_good.winfo_screenwidth()
    screenheight = window_function_good.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function_good.geometry('+{}+{}'.format(x, y))

    window_function_good.mainloop()


def add_customer():# 添加供应商界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function_customer
    global s1,s2,s3,s4,s5,s6,s7,s8,s9
    # 生成窗口
    window_function_customer = tk.Tk()
    # 窗口标题
    window_function_customer.title("添加供应商信息")
    # 窗口大小
    window_function_customer.geometry('400x700')

    # 生成标签
    tk.Label(window_function_customer, text="添加新供应商", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function_customer, text="请输入供应商编号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="请输入供应商名称：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="请输入供应商简称：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="请输入地址：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="请输入公司电话：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="请输入邮件：").grid(row=6, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="请输入联系人：").grid(row=7, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="请输入联系人电话：").grid(row=8, column=0, padx=20, pady=20)
    tk.Label(window_function_customer, text="备注：").grid(row=9, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    s7 = tk.StringVar()
    s8 = tk.StringVar()
    s9 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function_customer, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function_customer, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function_customer, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function_customer, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function_customer, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function_customer, show=None, textvariable=s6).grid(row=6, column=1)
    entry7 = tk.Entry(window_function_customer, show=None, textvariable=s7).grid(row=7, column=1)
    entry8 = tk.Entry(window_function_customer, show=None, textvariable=s8).grid(row=8, column=1)
    entry9 = tk.Entry(window_function_customer, show=None, textvariable=s9).grid(row=9, column=1)
    # 生成按钮
    button = tk.Button(window_function_customer, text="添加",command=add_gys).place(relx=0.3, rely=0.875)
    button2 = tk.Button(window_function_customer, text="返回", command=back3_add).place(relx=0.5, rely=0.875)
    # 显示窗口

    # 计算窗口居中的位置
    window_function_customer.update_idletasks()
    width = window_function_customer.winfo_width()
    height = window_function_customer.winfo_height()
    screenwidth = window_function_customer.winfo_screenwidth()
    screenheight = window_function_customer.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function_customer.geometry('+{}+{}'.format(x, y))

    window_function_customer.mainloop()



def add_pay_main():# 添加采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function_pay_main
    global s1,s2,s3,s4,s5,s6
    # 生成窗口
    window_function_pay_main = tk.Tk()
    # 窗口标题
    window_function_pay_main.title("添加采购主表信息")
    # 窗口大小
    window_function_pay_main.geometry('400x700')

    # 生成标签
    tk.Label(window_function_pay_main, text="添加新信息", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function_pay_main, text="请输入采购清单号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_main, text="请输入员工编号：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_main, text="请输入采购数量：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_main, text="请输入采购总价：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_main, text="请输入采购时间：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_main, text="备注：").grid(row=6, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function_pay_main, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function_pay_main, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function_pay_main, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function_pay_main, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function_pay_main, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function_pay_main, show=None, textvariable=s6).grid(row=6, column=1)
    # 生成按钮
    button = tk.Button(window_function_pay_main, text="添加", command=add_cgzb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function_pay_main, text="返回", command=back4_add).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function_pay_main.update_idletasks()
    width = window_function_pay_main.winfo_width()
    height = window_function_pay_main.winfo_height()
    screenwidth = window_function_pay_main.winfo_screenwidth()
    screenheight = window_function_pay_main.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function_pay_main.geometry('+{}+{}'.format(x, y))

    window_function_pay_main.mainloop()


def add_pay_detail():# 添加采购明细表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function_pay_detail
    global s1,s2,s3,s4,s5,s6,s7
    # 生成窗口
    window_function_pay_detail = tk.Tk()
    # 窗口标题
    window_function_pay_detail.title("添加采购明细表信息")
    # 窗口大小
    window_function_pay_detail.geometry('400x700')

    # 生成标签
    tk.Label(window_function_pay_detail, text="添加新信息", font=("黑体", 20)).grid(row=0, column=1, pady=10)
    tk.Label(window_function_pay_detail, text="请输入采购明细号：").grid(row=1, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_detail, text="请输入采购清单：").grid(row=2, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_detail, text="请输入商品编号：").grid(row=3, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_detail, text="请输入采购数量：").grid(row=4, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_detail, text="请输入商品单价：").grid(row=5, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_detail, text="请输入商品总价：").grid(row=6, column=0, padx=20, pady=20)
    tk.Label(window_function_pay_detail, text="备注：").grid(row=7, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    s2 = tk.StringVar()
    s3 = tk.StringVar()
    s4 = tk.StringVar()
    s5 = tk.StringVar()
    s6 = tk.StringVar()
    s7 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function_pay_detail, show=None, textvariable=s1).grid(row=1, column=1)
    entry2 = tk.Entry(window_function_pay_detail, show=None, textvariable=s2).grid(row=2, column=1)
    entry3 = tk.Entry(window_function_pay_detail, show=None, textvariable=s3).grid(row=3, column=1)
    entry4 = tk.Entry(window_function_pay_detail, show=None, textvariable=s4).grid(row=4, column=1)
    entry5 = tk.Entry(window_function_pay_detail, show=None, textvariable=s5).grid(row=5, column=1)
    entry6 = tk.Entry(window_function_pay_detail, show=None, textvariable=s6).grid(row=6, column=1)
    entry6 = tk.Entry(window_function_pay_detail, show=None, textvariable=s7).grid(row=7, column=1)
    # 生成按钮
    button = tk.Button(window_function_pay_detail, text="添加", command=add_cgmxb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function_pay_detail, text="返回", command=back5_add).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function_pay_detail.update_idletasks()
    width = window_function_pay_detail.winfo_width()
    height = window_function_pay_detail.winfo_height()
    screenwidth = window_function_pay_detail.winfo_screenwidth()
    screenheight = window_function_pay_detail.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function_pay_detail.geometry('+{}+{}'.format(x, y))

    window_function_pay_detail.mainloop()

def all_add():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("超市信息管理系统")
    window_choice.geometry('400x900')
    # 生成画布，销毁后生成新的画布实现跳转
    page = tk.Frame(window_choice)
    page.pack()

    tk.Label(window_choice, text="欢迎使用商城信息管理系统", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window_choice, text="添加员工表信息", command=add_employee).pack(pady=10)
    button2 = tk.Button(window_choice, text="添加商品表信息", command=add_good).pack(pady=10)
    button3 = tk.Button(window_choice, text="添加供应商表信息", command=add_customer).pack(pady=10)
    button4 = tk.Button(window_choice, text="添加采购主表信息", command=add_pay_main).pack(pady=10)
    button5 = tk.Button(window_choice, text="添加采购明细表信息", command=add_pay_detail).pack(pady=10)
    button6 = tk.Button(window_choice, text="返回",command=back_window).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()

###########################################################################################
def delete_employee():# 删除员工界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除员工信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入员工编号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_yg).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back1_delete).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def delete_good():# 删除商品界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除商品信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入商品编号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_sp).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back2_delete).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def delete_customer():# 删除供应商界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除供应商信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入供应商编号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_gys).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back2_delete).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def delete_pay_main():# 删除采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除采购主表信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入采购清单号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_cgzb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back4_delete).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def delete_pay_detail():# 删除采购明细表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("删除采购明细表信息")
    # 窗口大小
    window_function.geometry('400x700')

    # 生成标签
    tk.Label(window_function, text="请输入采购明细号：").grid(row=1, column=0, padx=20, pady=20)
    # 定义变量记录输入信息
    s1 = tk.StringVar()
    # 生成输入框
    entry1 = tk.Entry(window_function, show=None, textvariable=s1).grid(row=1, column=1)
    # 生成按钮
    button = tk.Button(window_function, text="确认", command=delete_cgmxb).place(relx=0.3, rely=0.8)
    button2 = tk.Button(window_function, text="返回", command=back5_delete).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def all_delete():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("超市信息管理系统")
    window_choice.geometry('400x900')
    # 生成画布，销毁后生成新的画布实现跳转
    page = tk.Frame(window_choice)
    page.pack()

    tk.Label(window_choice, text="欢迎使用商城信息管理系统", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window_choice, text="删除员工表信息", command=delete_employee).pack(pady=10)
    button2 = tk.Button(window_choice, text="删除商品表信息", command=delete_good).pack(pady=10)
    button3 = tk.Button(window_choice, text="删除供应商表信息", command=delete_customer).pack(pady=10)
    button4 = tk.Button(window_choice, text="删除采购主表信息", command=delete_pay_main).pack(pady=10)
    button5 = tk.Button(window_choice, text="删除采购明细表信息", command=delete_pay_detail).pack(pady=10)
    button6 = tk.Button(window_choice, text="返回",command=back2_window).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()

###########################################################################################
def select_employee():# 查询员工界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("员工信息")
    # 窗口大小
    window_function.geometry('400x700')
    select_yg()
    button1 = tk.Button(window_function, text="返回", command=back1_select).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def select_good():# 查询商品界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("商品信息")
    # 窗口大小
    window_function.geometry('400x700')
    select_sp()
    button1 = tk.Button(window_function, text="返回", command=back2_select).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def select_customer():# 查询供应商界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("供应商信息")
    # 窗口大小
    window_function.geometry('400x700')
    select_gys()
    button1 = tk.Button(window_function, text="返回", command=back3_select).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def select_pay_main():# 查询采购主表界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("采购主表信息")
    # 窗口大小
    window_function.geometry('400x700')
    select_cgzb()
    button1 = tk.Button(window_function, text="返回", command=back4_select).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def select_pay_detail():# 查询采购明细界面
    window_choice.destroy()
    # 构建全集变量，方便上面的函数调用
    global window_function
    global s1
    # 生成窗口
    window_function = tk.Tk()
    # 窗口标题
    window_function.title("采购明细信息")
    # 窗口大小
    window_function.geometry('400x700')
    select_cgmxb()
    button1 = tk.Button(window_function, text="返回", command=back5_select).place(relx=0.5, rely=0.8)
    # 显示窗口

    # 计算窗口居中的位置
    window_function.update_idletasks()
    width = window_function.winfo_width()
    height = window_function.winfo_height()
    screenwidth = window_function.winfo_screenwidth()
    screenheight = window_function.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_function.geometry('+{}+{}'.format(x, y))

    window_function.mainloop()

def all_select():
    global window_choice
    window_choice = tk.Tk()
    window_choice.title("超市信息管理系统")
    window_choice.geometry('400x900')
    # 生成画布，销毁后生成新的画布实现跳转
    page = tk.Frame(window_choice)
    page.pack()

    tk.Label(window_choice, text="欢迎使用商城信息管理系统", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window_choice, text="查看员工表信息", command=select_employee).pack(pady=10)
    button2 = tk.Button(window_choice, text="查看商品表信息", command=select_good).pack(pady=10)
    button3 = tk.Button(window_choice, text="查看供应商表信息", command=select_customer).pack(pady=10)
    button4 = tk.Button(window_choice, text="查看采购主表信息", command=select_pay_main).pack(pady=10)
    button5 = tk.Button(window_choice, text="查看采购明细表信息", command=select_pay_detail).pack(pady=10)
    button6 = tk.Button(window_choice, text="返回",command=back3_window).place(relx=0.5, rely=0.8)

    # 计算窗口居中的位置
    window_choice.update_idletasks()
    width = window_choice.winfo_width()
    height = window_choice.winfo_height()
    screenwidth = window_choice.winfo_screenwidth()
    screenheight = window_choice.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window_choice.geometry('+{}+{}'.format(x, y))

    window_choice.mainloop()

############################################################################################

#添加跳转
#主页面跳转添加功能界面
def change_add():
    window.destroy()
    all_add()
#添加功能界面返回主页面
def back_window():
    window_choice.destroy()
    mainpage()
#输入添加信息界面返回选表界面
def back1_add():
    window_function.destroy()
    all_add()
def back2_add():
    window_function_good.destroy()
    all_add()
def back3_add():
    window_function_customer.destroy()
    all_add()
def back4_add():
    window_function_pay_main.destroy()
    all_add()
def back5_add():
    window_function_pay_detail.destroy()
    all_add()
#-------------------------------------
def change_delete():
    window.destroy()
    all_delete()
#删除功能界面返回主页面
def back2_window():
    window_choice.destroy()
    mainpage()
def back1_delete():
    window_function.destroy()
    all_delete()
def back2_delete():
    window_function.destroy()
    all_delete()
def back3_delete():
    window_function.destroy()
    all_delete()
def back4_delete():
    window_function.destroy()
    all_delete()
def back5_delete():
    window_function.destroy()
    all_delete()
#---------------------------
def change_select():
    window.destroy()
    all_select()
#查询功能界面返回主页面
def back3_window():
    window_choice.destroy()
    mainpage()
def back1_select():
    window_function.destroy()
    all_select()
def back2_select():
    window_function.destroy()
    all_select()
def back3_select():
    window_function.destroy()
    all_select()
def back4_select():
    window_function.destroy()
    all_select()
def back5_select():
    window_function.destroy()
    all_select()
#################################################################################################

import tkinter as tk
from tkinter import messagebox


# 创建登录界面
def login_page():
    global root, id_entry, password_entry, level_entry
    root = tk.Tk()
    root.title("用户登录")
    root.geometry('400x200')

    tk.Label(root, text="编号：").grid(row=0, column=0, padx=20, pady=10)
    id_entry = tk.Entry(root)
    id_entry.grid(row=0, column=1)

    tk.Label(root, text="密码：").grid(row=1, column=0, padx=20, pady=10)
    password_entry = tk.Entry(root, show="*")
    password_entry.grid(row=1, column=1)

    tk.Label(root, text="级别：").grid(row=2, column=0, padx=20, pady=10)
    level_entry = tk.Entry(root)
    level_entry.grid(row=2, column=1)

    login_button = tk.Button(root, text="登录",
                             command=lambda: submit(id_entry.get(), password_entry.get(), level_entry.get()))
    login_button.place(relx=0.5, rely=0.7)

    # 计算窗口居中的位置
    root.update_idletasks()
    width = root.winfo_width()
    height = root.winfo_height()
    screenwidth = root.winfo_screenwidth()
    screenheight = root.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    root.geometry('+{}+{}'.format(x, y))

    root.mainloop()

def submit(input_id, input_password, input_level):
    connect = pymysql.connect(host="localhost", user="root", password="20050101", database="618")
    cursor = connect.cursor()

    sql = "SELECT * FROM 员工表"

    try:
        cursor.execute(sql)
        employees = cursor.fetchall()
        input_list = [str(input_id), str(input_password), str(input_level)]  # 用户输入的列表
        for employee in employees:
            employee_data_list = ([employee[0], employee[2], employee[3]])
            if input_list == employee_data_list:
                if input_list[2] == "00":  # 判断是否为管理员
                    messagebox.showinfo("登录成功", "管理员登录成功")
                    root.destroy()  # 关闭登录界面
                    mainpage()
                else:
                    messagebox.showinfo("登录成功", "普通用户登录成功")
                return

        messagebox.showerror("登录失败", "用户名或密码错误")

    except Exception as e:
        print("登录出错:", e)
        messagebox.showerror("错误", "登录出错")

    finally:
        connect.close()

# 主界面
def mainpage():
    global window
    window = tk.Tk()
    window.title("超市信息管理系统")

    # 打开图片文件
    image = Image.open("超市.jpg")
    photo = ImageTk.PhotoImage(image)
    window.photo = photo

    # 创建一个标签放置图片
    label = tk.Label(window, image=photo)
    label.place(x=0,y=0,relwidth=1,relheight=1)

    tk.Label(window, text="欢迎使用超市信息管理系统", font=("黑体", 20)).pack(pady=10)
    button1 = tk.Button(window, text="添加信息", command=change_add).pack(pady=10)
    button2 = tk.Button(window, text="删除信息", command=change_delete).pack(pady=10)
    button3 = tk.Button(window, text="修改信息").pack(pady=10)
    button4 = tk.Button(window, text="信息查询", command=change_select).pack(pady=10)

    # 计算窗口居中的位置
    window.update_idletasks()
    width = window.winfo_width()
    height = window.winfo_height()
    screenwidth = window.winfo_screenwidth()
    screenheight = window.winfo_screenheight()
    x = (screenwidth - width) // 2
    y = (screenheight - height) // 2
    window.geometry('+{}+{}'.format(x, y))

    window.mainloop()

login_page()

